import { watcher } from "@feng3d/watcher";
import { LatheGeometry, Vector2 } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class LatheGeometry3D extends BufferGeometry3D
{
    points = [new Vector2(0, -0.5), new Vector2(0.5, 0), new Vector2(0, 0.5)];
    segments = 12;
    phiStart = 0;
    phiLength = Math.PI * 2;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new LatheGeometry(this.points, this.segments, this.phiStart, this.phiLength);
        }

        return this.__geometry;
    }
    declare protected __geometry: LatheGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as LatheGeometry3D, ["points", "segments", "phiStart", "phiLength"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as LatheGeometry3D, ["points", "segments", "phiStart", "phiLength"], this._invalidate, this);
    }
}
